package work1
// 4：输出比10000大的10个质数
object NextPrimes {
  def main(args: Array[String]): Unit = {
    val primes = nextPrimes(10000, 10)
    println(s"比10000大的10个质数是：${primes.mkString(", ")}")
  }

  def nextPrimes(start: Int, count: Int): List[Int] = {
    var num = start + 1
    var primes = List[Int]()
    while (primes.length < count) {
      if (isPrime(num)) primes = primes :+ num
      num += 1
    }
    primes
  }

  def isPrime(n: Int): Boolean = {
    if (n <= 1) false
    else (2 to math.sqrt(n).toInt).forall(n % _ != 0)
  }
}
